package Servlets.seeker;

import Dao.EmployerDaoimpl;
import Entity.Employer;
import Entity.Seeker;
import Service.FettleServiceimpl;
import Service.SeekerServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deliver")

public class Deliver extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public Deliver() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        response.setContentType("text/html;charset=UTF-8");

        String eid = request.getParameter("eid");

        int sid = (int) request.getSession().getAttribute("seid");
        EmployerDaoimpl edl = new EmployerDaoimpl();
        SeekerServiceimpl se = new SeekerServiceimpl();
        int teid = Integer.parseInt(eid);
        String cw = null;
        FettleServiceimpl del = new FettleServiceimpl();
        try {
            Employer em = edl.SearchById(teid);
            String ename = em.getEname();
            String econtact = em.getContacter();
            String ep = em.getPhone();
            Seeker sm = se.SearchById(sid);
            String sname = sm.getSname();
            String sphone = sm.getSphone();
            cw = del.deliver(teid, sid, ename, econtact, ep, sname, sphone);


            if (cw.equals("投递成功")) {

                request.getRequestDispatcher("/Employerservlet").forward(request, response);

            } else if (cw.equals("已投递")) {

                request.setAttribute("cw2", "已投递");

                request.getRequestDispatcher("/Employerservlet").forward(request, response);

            }

        } catch (Exception e) {

// TODO Auto-generated catch block
            System.out.println("错误");
            e.printStackTrace();

        }

    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

        doGet(request, response);

    }


}
